package cn.ydt.ydt.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PasswordUtils {

    private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    public static String encode(String rawPassword) {
        // 加密过程
        // 使用Bcrypt算法加密
        String encodedPassword = passwordEncoder.encode(rawPassword);
        log.info("加密成功，密文为：{}",encodedPassword);
        return encodedPassword;
    }

    public static boolean matches(String rawPassword, String encodedPassword) {
        // 使用Bcrypt算法解密
        boolean matchResult = passwordEncoder.matches(rawPassword, encodedPassword);
        log.info("解密结果为：{}",matchResult);
        return matchResult;
    }
}
